import { request } from './request';
import axios from "axios";

//UserController
export function getUserByIdByPass(data) { //post接收的对象一定需要 命名为data，这样request.ts的transformRequest配置才可以识别
    let url = "/UserController/findByUserIdAndPassword"
    return request({
        url: url,
        method: 'post',
        data
    })
}

export function countUserById(userId){
    let url = "/UserController/countUserById/"
    return request({
        url: url.concat(userId),
        method: 'get',
    })
}

export function addUser(data){
    let url = "/UserController/addUser"
    return request({
        url: url,
        method: 'post',
        data
    })
}

//FoodController
export function listFoodByBusinessId(businessId){
    let url = "/FoodController/listFoodByBusinessId/"
    return request({
        url: url.concat(businessId),
        method: 'get',
    })
}



//BusinessController
export function getBusinessByBusinessId(businessId){
    let url = "/BusinessController/getBusinessById/"
    return request({
        url: url.concat(businessId),
        method: 'get',
    })
}

export function listAllBusinessByType(type){
    let url = "/BusinessController/listAllBusinessByType/"
    return request({
        url: url.concat(type),
        method: 'get',
    })
}

//CartController
export function removeCartByData(data) { //如果后端是@RequestParam的话，直接改成post方法（前后端都是
    let url = "/CartController/removeCart"
    return request({
        url: url,
        method: 'post',
        data
    })
}
export function addCart(data){
    let url = "/CartController/addCart"
    return request({
        url: url,
        method: 'post',
        data
    })
}
export function updateQuantity(uid,bid,fid,quantity){
    let urlUpdateCart = "/CartController/updateQuantity/"
    return request({
        url: urlUpdateCart.concat(uid,"/",bid,"/",fid,"/",quantity),
        method: 'get',
    })
}
export function findAllByUidOrByUidAndBid(data){
    let url = "/CartController/findAllByUidOrByUidAndBid"
    return request({
        url: url,
        method: 'post',
        data
    })
}

export function addDeliveryAddress(data){
    let urlAdd = "/DeliveryAddressController/addDeliveryAddress"
    return request({
        url:urlAdd,
        method:"post",
        data
    })
}

//DeliveryAddressController
export function getDeliveryAddressById(daId){
    let urlGet = "/DeliveryAddressController/getDeliveryAddressById/"
    return request({
        url: urlGet.concat(daId),
        method: 'get',
    })
}

export function updateDeliveryAddress(data){
    let urlAdd = "/DeliveryAddressController/updateDeliveryAddress"
    return request({
        url:urlAdd,
        method:"post",
        data
    })
}

export function getDeliveryAddressByUserId(userId){
    let urlGet = "/DeliveryAddressController/listDeliveryAddressByUserId/"
    return request({
        url: urlGet.concat(userId),
        method: 'get',
    })
}

export function removeDeliveryAddress(daId){
    let urlGet = "/DeliveryAddressController/removeDeliveryAddress/"
    return request({
        url: urlGet.concat(daId),
        method: 'get',
    })
}

//OrderController
export function listOrdersByUserId(userId){
    let urlGet = "/OrdersController/listOrdersByUserId/"
    return request({
        url: urlGet.concat(userId),
        method: 'get',
    })
}
export function createOrders(userId,bussinessId,daId,totalPrice){
    let urlGet = "/OrdersController/createOrders/"
    return request({
        url: urlGet.concat( userId,"/", bussinessId,"/", daId,"/", totalPrice),
        method: 'get',
    })
}

export function getOrdersById(orderId){
    let urlGet = "/OrdersController/getOrdersById/"
    return request({
        url: urlGet.concat( orderId),
        method: 'get',
    })
}